Grokking Scalable Systems for Interviews
Rate this course
Ask Author
Contribute
Back to course home

4% completed

Vote For New Content
Introduction
Course Overview
Who This Course Is for
Caching
What Is Negative Caching and When Should You Cache 404 or Empty Results?
What Is the Difference Between Soft TTL and Hard TTL, and Why Does It Matter?
How Can a Bloom Filter Reduce Cache or Database Load?
What Is Distributed Locking for Cache Rebuilds, and How Does It Prevent Cache Stampedes?
Load Balancing
What Are Sticky Sessions (Session Affinity) and When Should I Avoid Them?
What Is the Difference between Liveness Checks and Readiness Checks in Load Balancers?
What is Global Server Load Balancing (GSLB) and How GeoDNS and Anycast Work?
API Basics
What are the Main API Pagination Strategies (offset, cursor, keyset), and When Should I Use Each?
What are HTTP Conditional Requests (ETag, If‑None‑Match, Last‑Modified) and How They Reduce Load?
What Is the Difference between Rate Limiting and Throttling and Quotas?
What Are Idempotency Keys and How to Implement Them Safely for Payments
Databases
What are SQL Isolation Levels (Read Committed, Repeatable Read, Serializable), and What Anomalies Do They Prevent?
What Is a Write‑Ahead Log (WAL), and How Does It Ensure Durability?
What Is the Difference Between Synchronous and Asynchronous Replication, and When Should I Use Read Replicas?
What Is MVCC (Multi‑Version Concurrency Control), and How Does It Enable Concurrent Reads and Writes?
What Are Safe Patterns for Online Schema Changes vs. Offline Migrations?
Scalability
What is Little’s Law and How to Use It for Quick Capacity Estimates in System Design
How Can I do Back-of-the-Envelope Sizing for QPS, Bandwidth, Storage, and Peak vs. Average Load?
What are Cold Starts and Warm Starts, and Why Do They Matter for Performance?
Sharding and Partitioning
How Do I Choose a Good Shard Key and Avoid Hotspots (Bucketing and Key Randomization)?
What Are Range Sharding, Directory‑Based Sharding, and Geo‑Sharding, and What Are the Common Use Cases?
What Is the Difference Between Rendezvous Hashing and Consistent Hashing, and When Should I Use Each?
Messaging and Streaming
What Do At‑most‑once, At‑least‑once, And Exactly‑once Delivery Semantics Mean?
What Are Idempotent Producers And Consumers, And How Do De‑duplication Keys Work?
What Is Message Ordering, How Do Partition Keys Affect It, And When Can Ordering Break?
What Are Windowing And Watermarking In Streaming Systems, In Simple Terms?
Consistency and Replication
What Is Quorum (N, R, W), And Why Does R + W > N Give Strongly Consistent Reads?
What Are Common Conflict Resolution Strategies (Last‑write‑wins, Vector Clocks, Logical Clocks)?
What Are Read Repair, Hinted Handoff, And Anti‑entropy (Merkle Trees) In Eventually Consistent Systems?
Observability
What Is The Difference Between SLI, SLO, And SLA, And Can You Give Simple Examples?
What Is Opentelemetry, And How Do Traces, Spans, Metrics, And Logs Fit Together?
What Is An Error Budget, And How Should It Guide Release Decisions?
Security
What Are The Trade‑offs Between Server‑stored Sessions And JWTs for Authentication?
What Is The Difference Between TLS And MTLS, And When Is MTLS Appropriate For Service‑to‑service Auth?
What Is Secrets Management, And How Do Environment Variables, KMS, And Vault Compare?
What Is A Replay Attack, And How Is It Different from Idempotency Issues?
Networking
What Are The Differences Between TCP, UDP, And QUIC, And When Should I Use Each?
What Is The Difference Between A Forward Proxy, A Reverse Proxy, And NAT?
What Changed From HTTP/1.1 To HTTP/2 To HTTP/3, And What Are Head‑of‑line Blocking And Multiplexing?
Storage
What Is the Difference Between Content‑Addressable Storage and Location‑Based Addressing?
What Are Checksums and Etags, and How Do MD5/SHA Compare to CRC for Integrity?
What Are Hot, Warm, Cold, and Archive Storage Tiers, and When Should I Use Each?
Design Patterns
What Is the Outbox Pattern, and How Does Change Data Capture (CDC) Work at a High Level?
What Is CQRS (Command Query Responsibility Segregation), and When Should I Consider It?
What Are the Differences Between a Circuit Breaker, Retry With Backoff, and Rate Limiting?
What Are RPO and RTO, and How Do They Differ in Disaster Recovery Planning?
What Is the Difference Between Active‑Active and Active‑Passive Architectures?
What Is Graceful Degradation, and How Do Feature Flags Help Availability?
What Are the Differences Between UUID, ULID, KSUID, and Snowflake IDs, and How Do I Choose?
How Do Snowflake‑Style IDs Work (Timestamp, Worker, Sequence), and What Problems Do They Solve?
What Is the Difference Between Wall‑Clock Time and Monotonic Time, and Why Is Clock Skew Hard?
Final Words
Key Takeaways
What To Learn Next
What Are the Differences Between a Circuit Breaker, Retry With Backoff, and Rate Limiting?

Circuit breakers stop repeated calls to a failing service after a failure threshold is met, retry with exponential backoff automatically re-attempts failed operations with progressively longer waits, and rate limiting caps the number of requests per time unit to prevent overload.

What Is a Circuit Breaker?

A circuit breaker is a protection mechanism inspired by electrical circuits.

When a service or resource fails repeatedly, the circuit breaker “opens” and immediately rejects further calls instead of letting each request time out or fail.

By opening the circuit after a configurable number of failures (e.g. 5 errors in a row), the system avoids wasting resources on an already-broken service.

After a cool-down period the breaker moves to a half-open state to test the service again, and if calls succeed it closes the circuit back to normal operation.

This stateful pattern helps prevent cascading failures: for example, if a downstream API is down, the circuit breaker trips and your system can fall back quickly rather than slowing down or crashing.

Key points:

  • Circuit breakers monitor failures. When the error rate is too high, they open and immediately reject calls.

  • In the Closed state, calls pass through normally; in Open, calls fail fast; in Half-Open, a few test calls are allowed to check recovery.

  • Common use cases include protecting microservices or external API calls. For instance, if a payment service fails, a circuit breaker will quickly halt calls and invoke a fallback response.

What Is Retry with Exponential Backoff?

Retry with backoff is a strategy for handling transient failures (temporary glitches).

Instead of failing on the first error, the system retries the operation a few times, waiting longer between each attempt (often doubling the wait each time, known as exponential backoff).

For example, if an HTTP request to a service fails due to a brief network hiccup, the client might retry after 1s, then 2s, then 4s.

Exponential backoff helps avoid immediately re-overloading the service and spreads out retry attempts across time.

This pattern is stateless (each retry is independent) and assumes errors are short-lived.

Key points:

  • Transient faults: Use retry when failures are likely temporary (e.g. brief network outage, a busy server). You give the system a chance to recover on its own.

  • Backoff delays: Each retry waits longer than the last (e.g. 1s, 2s, 4s…). Many implementations add a random “jitter” so that many clients don’t retry in lockstep.

  • Retry limits: You set a maximum number of retries to avoid endless loops. After that, you assume the fault isn’t transient. A fallback or error is then returned.

What Is Rate Limiting?

Rate limiting (or throttling) controls traffic by putting an upper bound on requests per time unit. It is not triggered by failures at all but by sheer request volume.

Rate Limiting
Rate Limiting

For example, an API might allow only 100 calls per minute per user.

Once the limit is reached, further calls are paused or rejected until the next time window. This ensures fair use and protects the service from overload or abuse.

Rate limiting is a standard practice in public APIs, login attempts (to prevent brute-force attacks), and any high-throughput system.

Key points:

  • Traffic control: Rate limiting enforces a fixed capacity (e.g. 10 requests/sec) to keep systems responsive.

  • Algorithms: Common methods include token buckets or leaky buckets, which smooth bursts of traffic into allowed rates.

  • Typical uses: API gateways, web servers, and messaging systems use rate limiting to prevent spikes and ensure stability. For example, cloud services often return HTTP 429 “Too Many Requests” when a client exceeds its allotted rate.

Differences and When to Use Which

  • Trigger: Circuit breakers react to failures (error rates), retry-with-backoff reacts to errors/timeouts by retrying, and rate limiting reacts to high request volume.

  • Purpose: Circuit breakers fail fast to protect the system during persistent problems. Retry-with-backoff keeps trying to overcome fleeting issues. Rate limiting prevents overload upfront by capping throughput.

  • State: Circuit breakers are stateful (they track recent failures and have Closed/Open/Half-Open states). Retries are stateless retries (each attempt is separate). Rate limiting may be stateful (tracking counts in time) but is not based on failures, only counters.

  • Best for: Use retry when errors are likely transient (e.g. a brief network glitch). Use circuit breaker when errors may be persistent (e.g. a down service) to avoid wasting resources. Use rate limiting to protect against excessive load or abuse by limiting calls per second/minute.

Example scenarios:

  • A web microservice calls an external API. If the API sometimes fails with a 502, the client can retry after a short delay with backoff. If the API keeps failing, a circuit breaker opens and prevents further calls, returning a cached or default response. Separately, the client’s calls to the API are also throttled to 50 QPS by a rate limiter, so even if the API is healthy, it cannot be overloaded.

  • For login attempts, a rate limiter prevents brute-force (e.g. max 5 logins per minute). If a login service is temporarily down, a retry mechanism might try again after a few seconds. If many logins start failing repeatedly, a circuit breaker could trip to prevent further load on that service.

In summary, retry (with backoff) and circuit breaker are complementary resilience patterns: retries assume faults will clear soon, whereas circuit breakers assume a fault may last long and proactively stop calls.

Rate limiting is about controlling request volume rather than handling failures. By using the right strategy (or combination) in context, systems stay more robust and maintain performance.

What Is CQRS (Command Query Responsibility Segregation), and When Should I Consider It?
What Are RPO and RTO, and How Do They Differ in Disaster Recovery Planning?
Mark as Completed

On this page

What Is a Circuit Breaker?

What Is Retry with Exponential Backoff?

What Is Rate Limiting?

Differences and When to Use Which